//package com.jiegui.mqtt.callback;
//import com.jiegui.common.utils.spring.SpringUtils;
//import cn.hutool.core.util.HexUtil;
//import com.jiegui.mqtt.callback.CmdFeedBackUtils;
//import com.jiegui.mqtt.config.MqttConfig;
//import lombok.extern.slf4j.Slf4j;
//import org.eclipse.paho.client.mqttv3.IMqttAsyncClient;
//import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
//import org.eclipse.paho.client.mqttv3.MqttCallbackExtended;
//import org.eclipse.paho.client.mqttv3.MqttMessage;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Configuration;
//
//import java.util.Objects;
//
//@Slf4j
//@Configuration
//public class MqttProviderCallBack implements MqttCallbackExtended {
//
//	@Value("${mqtt.termTopic:}")
//	private String  termTopic;
//
//
//
//	@Override
//	public void connectionLost(Throwable throwable) {
//		log.warn("MQTT 断开了连接 ：{}", throwable);
//	}
//
//	@Override
//	public void messageArrived(String topic, MqttMessage message) throws Exception {
//
//		String hexData = HexUtil.encodeHexStr(message.getPayload()).replaceAll("(.{2})", "$1 ");
//		log.info("接收到主题为{}的消息{}", topic, hexData);
//		String[] data = hexData.split(" ");
//
//		if (data.length < 8) { // 异常数据
//			return;
//		}
//		// 指令
//		String cmdType = data[6];
//		// 设备编号
//		String deviceNo = topic.split("/")[3];
//		CmdFeedBackUtils.analysis(deviceNo, data);
//	}
//
//	@Override
//	public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
//		IMqttAsyncClient client = iMqttDeliveryToken.getClient();
//		log.info("{}发布消息成功", client.getClientId());
//	}
//
//	@Override
//	public void connectComplete(boolean b, String s) {
//		log.info("MQTT 连接已完成... params: b[{}], s[{}]", b, s);
//		MqttConfig mqttClient = SpringUtils.getBean(MqttConfig.class);
//		mqttClient.subscribe(new String[] { MqttConfig.ONLINE_TOPIC, termTopic }, new int[] { 1, 1 });
//	}
//}
